import axios from 'axios'
import store from '@/store'
// create an axios instance
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})

// 请求拦截
service.interceptors.request.use(config => {
  // 如果有token,就传token
  if (store.getters.token && !config.noToken) {
    config.headers.Authorization = 'Bearer ' + store.getters.token
  }
  return config
}, err => {
  return Promise.reject(new Error(err))
})
export default service
